package lazy.tool;

import lazy.util.StringUtils;

public class JdbcUrl {
	private DBType dbType;
	private String address;
	private String port;
	private String schema;
	private String jdbcUrl;
	
	public JdbcUrl(DBType dbType, String address, String schema) {
		this(dbType, address, dbType==DBType.MySQL?"3306":dbType==DBType.MSSQLServer?"1433":null, schema);
	}
	public JdbcUrl(DBType dbType, String address, String port, String schema) {
		if(dbType==null || !StringUtils.hasText(address) || !StringUtils.hasText(port) || !StringUtils.hasText(schema))
			throw new IllegalArgumentException();
		this.dbType = dbType;
		this.address = address;
		this.port = port;
		this.schema = schema;
	}
	public DBType getDbType() {
		return dbType;
	}
	public String getAddress() {
		return address;
	}
	public String getPort() {
		return port;
	}
	public String getSchema() {
		return schema;
	}
	public String getJdbcUrl() {
		if(jdbcUrl==null) {
			jdbcUrl = JdbcUrlUtils.getJdbcUrl(dbType, address, port, schema);
		}
		return jdbcUrl;
	}
}
